package uk.co.douglashoskins.weathercompare.util;

import henson.midp.Float11;

public class Weather {
	public static final int CLOUD = 0;
	public static final int FOG = 1;
	public static final int RAIN = 2;
	public static final int SUNNY_INTERVALS = 3;
	public static final int SUN = 4;
	public static final int SNOW = 5;
	public static final int THUNDERSTORM = 6;
	
	public static int toFahr(int celsius) {
		return celsius * 9 / 5 + 32;
	}
	
	public static int toCels(int fahr) {
		return fahr - 32 * 5 / 9;
	}
	
	public static double haversine(double lat1, double lng1, double lat2, double lng2) {
	    double earthRadius = 3958.75;
	    double dLat = Math.toRadians(lat2-lat1);
	    double dLng = Math.toRadians(lng2-lng1);
	    double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
	               Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
	               Math.sin(dLng/2) * Math.sin(dLng/2);
	    double c = 2 * Float11.atan2(Math.sqrt(a), Math.sqrt(1-a));
	    double dist = earthRadius * c;

	    return dist;
    }
}
